<?php

class BookOfWeekController extends Controller
{
	public function actionIndex()
	{
	$dataProvider = $this->getBookOfWeek();
	//Yii::app()->end();
		$this->render('index',array('dataProvider'=>$dataProvider));
	}
	public function getBookOfWeek()
	{
		$now = date('Y-m-d');
		$week = strtotime(date("Y-m-d", strtotime($now)) . " -1 week");
		$lw = strftime("%Y-%m-%d",$week); 
		$condition = "createddate <= '$now 23:59:59' and createddate >= '$lw 00:00:00'";
		//echo $condition;
		//Yii::app()->end();
		$dataProvider=new CActiveDataProvider(Book::model(),
			array(
			'criteria'=>array(
				'condition'=>$condition,
				'order'=>'point desc, rateclick desc, downloadbookcount desc',
				'limit'=>8,
				),
			'pagination'=>array(
			'pageSize'=>5,
    ),
			));
			return $dataProvider;
	}
	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}